import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;



public class Fruit {

	public static void main(String[] args) {

		Scanner cin = new Scanner(System.in);
		while (cin.hasNextInt()) {
			int n = cin.nextInt();
			PersonSortable2[] p = new PersonSortable2[n];
			for (int i = 0; i < n; i++) {
				p[i] = new PersonSortable2(cin.next(), cin.nextInt());

			}

			Arrays.sort(p, new NameComparator());
			System.out.println("NameComparator:sort");
			for (PersonSortable2 nameComparator : p) {
				System.out.println(nameComparator);
			}
			Arrays.sort(p, new AgeComparator());
			System.out.println("AgeComparator:sort");
			for (PersonSortable2 ageComparator : p) {
				System.out.println(ageComparator);
			}

			System.out.println(Arrays.toString(NameComparator.class
					.getInterfaces()));
			System.out.println(Arrays.toString(AgeComparator.class
					.getInterfaces()));
		}
	}
}

class NameComparator implements Comparator<PersonSortable2> {

	public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
		// TODO Auto-generated method stub
		return arg0.getName().compareTo(arg1.getName());
	}

}

class AgeComparator implements Comparator<PersonSortable2> {

	public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
		// TODO Auto-generated method stub
		return arg0.getAge() - arg1.getAge();
	}

}
class PersonSortable2 {
	private String name;
	private int age;

	public PersonSortable2(String name, int age) {
		this.name = name;
		this.age = age;

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return this.name + "-" + this.age;
	}
}

// Arrays.sort(s, new Comparator<PersonSortable2>() {
//
// public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
// // TODO Auto-generated method stub
// return arg0.getName().compareTo(arg1.getName());
// }

// });
// System.out.println("NameComparator:sort");
// for (PersonSortable2 t : s) {
// System.out.println(t);
// }
 Arrays.sort(s, new Comparator<PersonSortable2>() {

 public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
 // TODO Auto-generated method stub
 return arg0.getAge() - arg1.getAge();
 }

 });
// System.out.println("AgeComparator:sort");
// for (PersonSortable2 t : s) {
// System.out.println(t);
// }